<template>
  <div class="login" id="login">
	    <img src="../assets/img/bgImg.jpg" class="bgImg">
		<div class="content">
			<div class="bidTitle">共读书房登录</div>
			<div class="logCon">
				<div class="line"><span>账号:</span>
				<input class="bt_input" type="text" v-model="name"></div>
				<div class="line"><span>密码:</span>
				<input class="bt_input" type="password" v-model="pwd"></div>
				<button type="button" class="logingBut" @click="login">登录</button>
			</div>
		</div>
  </div>
</template>

<script>
export default {
	name:'login',
	data(){
		return{
			name:'',
			pwd:''
		}
	},
	computed: {
      user(){
        return this.$store.state.user.userObj
      }
    },
	methods:{
		login(){
			var that = this
			if(!that.name){
				that.$message({
					message: '账号不为空',
					type: 'warning',
					duration:1000
				});
			}
			if(!that.pwd){
				that.$message({
					message: '密码不为空',
					type: 'warning',
					duration:1000
				});
			}
			var params = {}
			params.ACTIONNAME = 'login';
			params.phone = that.name;
			params.pwd = that.$md5(that.pwd);
			this.$get(params).then(res => {
				console.log(res)
				if(res.SUCCESS){
					that.$message({
						message: "登录成功",
						type: 'success',
						duration:1000
					});
					if(res.DATA.OBJID){
						window.localStorage.setItem('token',res.DATA.OBJID)
						window.localStorage.setItem('uid',res.DATA.OBJID)
					}
					if(res.DATA.YHMC){window.localStorage.setItem('userName',res.DATA.YHMC)}
					if(res.DATA.TXTP){window.localStorage.setItem('userImg',res.DATA.TXTP)}
					if(res.DATA.YHLX){window.localStorage.setItem('userType',res.DATA.YHLX)}
					// window.localStorage.setItem('token',res.DATA.OBJID)
					// window.localStorage.setItem('uid',res.DATA.OBJID)
					// window.localStorage.setItem('userName',res.DATA.YHMC)
					// window.localStorage.setItem('userImg',res.DATA.TXTP)
					// window.localStorage.setItem('userType',res.DATA.YHLX)

					/**用户信息修改需要保存的信息
					 * 
					 * 1，手机号
					 * 2，名称  userName
					 * 3，介绍
					 * 4，地址
					 * 5，头像
					 */
					// window.localStorage.setItem('phone',res.DATA.SJHM)
					// window.localStorage.setItem('introduce',res.DATA.JJ)
					// window.localStorage.setItem('address',res.DATA.XXDZ)
					// window.localStorage.setItem('headImg',res.DATA.TXTP)

					if(res.DATA.SJHM){window.localStorage.setItem('phone',res.DATA.SJHM)}
					if(res.DATA.JJ){window.localStorage.setItem('introduce',res.DATA.JJ)}
					if(res.DATA.XXDZ){window.localStorage.setItem('address',res.DATA.XXDZ)}
					if(res.DATA.TXTP){window.localStorage.setItem('headImg',res.DATA.TXTP)}


					that.$router.push("/")
				}else{
					that.$message({
						message: res.MSG,
						type: 'error',
						duration:1000
					});
				}
			})
		}
	}
}
</script>

<style scoped>
	@import url(../assets/css/login.css);
</style>